/*
 * @lc app=leetcode.cn id=844 lang=java
 *
 * [844] 比较含退格的字符串
 */

// @lc code=start
class Solution {
    public boolean backspaceCompare(String s, String t) {
        StringBuilder ss1 = new StringBuilder();
        StringBuilder ss2 = new StringBuilder();

        for(char c : s.toCharArray()) {
            if(c != '#') {
                ss1.append(c);
            } else if(ss1.length() > 0) {
                ss1.deleteCharAt(ss1.length() - 1);
            }
        }

        for(char c : t.toCharArray()) {
            if(c != '#') {
                ss2.append(c);
            } else if(ss2.length() > 0) {
                ss2.deleteCharAt(ss2.length() - 1);
            }
        }

        return ss1.toString().equals(ss2.toString());
    }
}
// @lc code=end

